package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ Description：TODO 设置默认页面
 * @ Author：wzj
 * @ Date：2018/12/22 9:39
 */
@SpringBootConfiguration
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    private MyInterceptor myInterceptor;

    /**
     * 设置默认首页,不设置默认为index.html
     * @param registry
     */
//    @Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/demo").setViewName("ss");
//        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
//    }

    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("addInterceptors");
        registry.addInterceptor(myInterceptor).addPathPatterns("/**").excludePathPatterns("/demo");
    }
}
